package com.dt.platform.generator.module.hr;


import com.dt.platform.constants.db.HrTables;
import com.dt.platform.constants.enums.common.StatusEnableEnum;
import com.dt.platform.constants.enums.hr.PersonBillStatusEnum;
import com.dt.platform.domain.hr.Person;
import com.dt.platform.domain.hr.PositionInfo;
import com.dt.platform.domain.hr.meta.PersonMeta;
import com.dt.platform.domain.hr.meta.PersonTransferActMeta;
import com.dt.platform.domain.hr.meta.PositionInfoMeta;
import com.dt.platform.generator.config.Config;
import com.dt.platform.proxy.hr.PersonServiceProxy;
import com.dt.platform.proxy.hr.PositionInfoServiceProxy;
import com.github.foxnic.generator.config.WriteMode;
import org.github.foxnic.web.domain.hrm.Employee;
import org.github.foxnic.web.domain.hrm.Organization;
import org.github.foxnic.web.domain.hrm.Position;
import org.github.foxnic.web.domain.hrm.meta.EmployeeMeta;
import org.github.foxnic.web.domain.hrm.meta.PositionMeta;
import org.github.foxnic.web.domain.system.DictItem;
import org.github.foxnic.web.domain.system.meta.DictItemMeta;
import org.github.foxnic.web.proxy.system.DictItemServiceProxy;


public class ActPersonTranferGtr extends BaseCodeGenerator {
    public ActPersonTranferGtr() {
        super(HrTables.HR_PERSON_TRANSFER_ACT.$TABLE,"666943320815042560");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());

        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.ID).basic().hidden(true);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.CONTENT).search().fuzzySearch();

        cfg.getPoClassFile().addSimpleProperty(Person.class,"person","person","person");
        cfg.getPoClassFile().addSimpleProperty(DictItem.class,"typeDict","typeDict","typeDict");
        cfg.getPoClassFile().addSimpleProperty(Employee.class,"oper","oper","oper");

        cfg.getPoClassFile().addSimpleProperty(Position.class, "orgPos","主岗", "作为员工时，所属的主岗");
        cfg.getPoClassFile().addSimpleProperty(PositionInfo.class, "posInfo","主岗", "作为员工时，所属的主岗");
        cfg.getPoClassFile().addSimpleProperty(Organization.class, "org","部门", "作为员工时，部门");
        cfg.getPoClassFile().addSimpleProperty(String.class, "orgPosId","主岗ID","只有一个");

        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TRANSFER_DATE).form().validate().required().form().dateInput().format("yyyy-MM-dd").search().range();
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TRANSFER_DATE).search().range();
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.OPER_TIME).form().dateInput().format("yyyy-MM-dd").search().range();
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.OPER_TIME).search().range();
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TRANSFER_DATE).search().range();

        cfg.view().search().inputLayout(
                new Object[]{
                        HrTables.HR_PERSON_TRANSFER_ACT.STATUS,
                        HrTables.HR_PERSON_TRANSFER_ACT.TRANSFER_TYPE,
                        HrTables.HR_PERSON_TRANSFER_ACT.PERSON_ID,
                        HrTables.HR_PERSON_TRANSFER_ACT.OPER_USER_ID,
                },
                new Object[]{
                        HrTables.HR_PERSON_TRANSFER_ACT.TRANSFER_DATE,
                        HrTables.HR_PERSON_TRANSFER_ACT.OPER_TIME,
                }

        );

        cfg.view().list().disableBatchDelete();




        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.UPDATE_TIME).form().table().disable(true);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.CREATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.CREATE_TIME).form().table().disable(true);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.NOTE).form().table().disable(true);

//        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TO_POS).form().table().disable(true);
//        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TO_POS_STATUS).form().table().disable(true);
//        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TO_ORG_POS_STATUS).form().table().disable(true);

        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.STATUS).form().radioBox().enumType(PersonBillStatusEnum.class).defaultIndex(0);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TO_ORG_POS_STATUS).form().validate().required().form().radioBox().enumType(StatusEnableEnum.class).defaultIndex(1);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TO_POS_STATUS).form().validate().required().form().radioBox().enumType(StatusEnableEnum.class).defaultIndex(1);

        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.PERSON_ID).form().validate().required().form().selectBox()
                .queryApi(PersonServiceProxy.QUERY_PAGED_LIST)
                .paging(true).filter(true).toolbar(false)
                .valueField(PersonMeta.ID).
                textField(PersonMeta.NAME).
                fillWith(PersonTransferActMeta.PERSON).muliti(false);



        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TO_ORG_POS)
                .form().button().choosePosition(true)
                .table().sort(false)
                .table().fillBy(EmployeeMeta.PRIMARY_POSITION, PositionMeta.FULL_NAME)
                .search().hidden();

        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TO_POS)
                .form().validate().required().form().selectBox().queryApi(PositionInfoServiceProxy.QUERY_PAGED_LIST)
                .paging(false).filter(false).toolbar(false)
                .valueField(PositionInfoMeta.ID).
                textField(PositionInfoMeta.NAME).
                fillWith(PersonTransferActMeta.POS_INFO).muliti(false);

        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.TRANSFER_TYPE)
                .form().validate().required().form().selectBox().queryApi(DictItemServiceProxy.QUERY_LIST+"?dictCode=hr_person_transfer_type")
                .paging(false).filter(false).toolbar(false)
                .valueField(DictItemMeta.CODE).
                textField(DictItemMeta.LABEL).
                fillWith(PersonTransferActMeta.TYPE_DICT).muliti(false);

        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.OPER_USER_ID).table().fillBy("oper","name");
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.OPER_USER_ID).form().readOnly().form()
                .button().chooseEmployee(true);

        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.FILE_IDS).form().table().disable(true);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.FILE_IDS).form().upload().maxFileCount(3).acceptAllType();
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.CONTENT).form().validate().required().form().textArea().height(80);
        cfg.view().field(HrTables.HR_PERSON_TRANSFER_ACT.NOTE).form().textArea().height(80);

        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);


        cfg.view().search().rowsDisplay(1);
        cfg.view().formWindow().width("80%");;
        cfg.view().formWindow().bottomSpace(100);
        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_PERSON_TRANSFER_ACT.PERSON_ID,
                        HrTables.HR_PERSON_TRANSFER_ACT.OPER_USER_ID,
                },
                new Object[] {
                        HrTables.HR_PERSON_TRANSFER_ACT.TRANSFER_TYPE,
                        HrTables.HR_PERSON_TRANSFER_ACT.TRANSFER_DATE,

                }
        );
        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_PERSON_TRANSFER_ACT.CONTENT,

                }
        );
        cfg.view().form().addGroup("部门调动",
                new Object[] {
                        HrTables.HR_PERSON_TRANSFER_ACT.TO_ORG_POS_STATUS,
                        HrTables.HR_PERSON_TRANSFER_ACT.TO_ORG_POS,
                },
                new Object[] {
                        HrTables.HR_PERSON_TRANSFER_ACT.TO_POS_STATUS,
                        HrTables.HR_PERSON_TRANSFER_ACT.TO_POS,
                }
        );

        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_PERSON_TRANSFER_ACT.FILE_IDS,
                }
        );
        cfg.view().list().operationColumn().addActionButton("确认","confirmData","confirm-data-button");
        cfg.view().list().addJsVariable("CUR_EMP_ID","[[${curEmpId}]]","curEmpId");
        cfg.view().form().addJsVariable("CUR_EMP_ID","[[${curEmpId}]]","curEmpId");
        cfg.view().form().addJsVariable("CUR_USER_NAME","[[${curUserName}]]","curUserName");
        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //页面控制器
                .setBpmEventAdaptor(WriteMode.COVER_EXISTS_FILE)
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE) //列表HTML页
                .setExtendJsFile(WriteMode.IGNORE);
        //生成代码
        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        ActPersonTranferGtr g=new ActPersonTranferGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
       // System.out.println("############"+g.getTablePrefix());
       // g.removeByBatchId("801716675761143808");
      //  //生成菜单
   //    g.generateMenu(PersonTransferActServiceProxy.class, PersonTransferActPageController.class);
    }
}
